package com.sunforum.forum.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sunforum.common.annotation.Log;
import com.sunforum.common.core.controller.BaseController;
import com.sunforum.common.core.domain.AjaxResult;
import com.sunforum.common.enums.BusinessType;
import com.sunforum.forum.domain.PcTag;
import com.sunforum.forum.service.IPcTagService;
import com.sunforum.common.utils.poi.ExcelUtil;
import com.sunforum.common.core.page.TableDataInfo;

/**
 * pc_标签Controller
 * 
 * @author sunforum
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/forum/tag")
public class PcTagController extends BaseController
{
    @Autowired
    private IPcTagService pcTagService;

    /**
     * 查询pc_标签列表
     */
    @PreAuthorize("@ss.hasPermi('forum:tag:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcTag pcTag)
    {
        startPage();
        List<PcTag> list = pcTagService.selectPcTagList(pcTag);
        return getDataTable(list);
    }

    /**
     * 导出pc_标签列表
     */
    @PreAuthorize("@ss.hasPermi('forum:tag:export')")
    @Log(title = "pc_标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcTag pcTag)
    {
        List<PcTag> list = pcTagService.selectPcTagList(pcTag);
        ExcelUtil<PcTag> util = new ExcelUtil<PcTag>(PcTag.class);
        util.exportExcel(response, list, "pc_标签数据");
    }

    /**
     * 获取pc_标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('forum:tag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(pcTagService.selectPcTagById(id));
    }

    /**
     * 新增pc_标签
     */
    @PreAuthorize("@ss.hasPermi('forum:tag:add')")
    @Log(title = "pc_标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcTag pcTag)
    {
        return toAjax(pcTagService.insertPcTag(pcTag));
    }

    /**
     * 修改pc_标签
     */
    @PreAuthorize("@ss.hasPermi('forum:tag:edit')")
    @Log(title = "pc_标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcTag pcTag)
    {
        return toAjax(pcTagService.updatePcTag(pcTag));
    }

    /**
     * 删除pc_标签
     */
    @PreAuthorize("@ss.hasPermi('forum:tag:remove')")
    @Log(title = "pc_标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(pcTagService.deletePcTagByIds(ids));
    }
}
